package com.example.easybuy.controller;


import com.example.easybuy.pojo.EasybuyUserAddress;
import com.example.easybuy.service.EasybuyUserAddressService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 张子晨
 * @since 2021-03-12
 */
@RestController
@RequestMapping("/easybuyUserAddress")
public class EasybuyUserAddressController {

    @Autowired
    EasybuyUserAddressService easybuyUserAddressService;

    @RequestMapping("/getAllAddressByUserId")
    public List<EasybuyUserAddress> getAllAddressByUserId(Integer userId) {
        List<EasybuyUserAddress> userAddressList = easybuyUserAddressService.getAllAddressByUserId(userId);
        return userAddressList;
    }

    @RequestMapping("/getAddressbyAddressId")
    public EasybuyUserAddress getAddressbyAddressId(Integer addressId) {
        return easybuyUserAddressService.getAddressbyAddressId(addressId);
    }

    @RequestMapping("/addUserAddress")
    public int addUserAddress(@RequestParam("addr") String addr,
                                             @RequestParam("mark") String mark,
                                             @RequestParam("userId") String userId){
        Map<String,Object> map=new HashMap<>();
        map.put("address",addr);
        map.put("remark",mark);
        map.put("userId",Integer.parseInt(userId));
        map.put("createTime",new Date());
        return easybuyUserAddressService.addUserAddress(map);
    }

}

